$(document).ready(function(){
	$("#functionNav").attr("href",navAddr);
	//获取查询条件
	var searchParams =$("#form1").serializeObject();	
	//初始化寄存单据Table	
	createTableOrderBy('#jcdjTable',ProjectName+'/colmanage.getLsDjList.do','id',tblColTitle,searchParams);	
	//点击查询按钮
	 $("#search_btn").click(function(){
		 refreshTable('#jcdjTable','#form1');
	 });
	//新建寄存单据按钮
	$("#addJcdj_btn").click(function(){
		window.location.href = "jcdjInfo.html";
	})	
	
	//初始化寄存藏品Table	
	var searchJccpParams =$("#form2").serializeObject();	
	$("#jccpList_btn").click(function(){		
		createTableOrderBy('#jccpTable',ProjectName+'/colmanage.getLsCpList.do','id',jccpColTitle,searchJccpParams);
	})
	//点击藏品查询按钮
	 $("#schCp_btn").click(function(){
		 refreshTable('#jccpTable','#form2');
	 });
})

//删除寄存单据
function delDj(id){
	bootbox.setLocale("zh_CN");
	bootbox.confirm("删除寄存单据后，该单据中的寄存藏品和相关资料也会被删除，确认要删除么？",function(r){
		if(r){
			var params = new Object();
			var deldjJson = ajaxResult("get",false,ProjectName+"/colmanage.deleteLsDj.do",{'id':id});
			if(deldjJson.status=='ok'){
				$('#jcdjTable').bootstrapTable('refresh');
			}else{
				alertFunc(delyxJson.error);
			}	
		}
	});
}

//结束寄存单据
function finishDj(id){
	bootbox.setLocale("zh_CN");
	bootbox.confirm("您确定结束寄存吗？",function(r){
		if(r){
			var dbResult = ajaxResult("get",false,ProjectName+"/colmanage.finishLsDj.do",{'id':id});
			if(dbResult["status"] == 'ok'){
			   alertFunc("结束寄存成功！");
			   $('#jcdjTable').bootstrapTable('refresh');
		    }else{
			   alert(dbResult["error"]);
		    }
		}
	});
}
//结束寄存藏品
function finishJccp(id,lsdjbh){
	bootbox.setLocale("zh_CN");
	bootbox.confirm("您确定结束寄存吗？",function(r){
		if(r){
			var params = new Object();
			params["ids"] = id;
			params["lsdjbh"] = lsdjbh;
			var dbResult = ajaxResult("get",false,ProjectName+"/colmanage.finishLsCp.do",params);
			if(dbResult["status"] == 'ok'){
			   alertFunc("结束寄存成功！");
			   $('#jccpTable').bootstrapTable('refresh');
		    }else{
			   alert(dbResult["error"]);
		    }
		}
	});
}

var tblColTitle = [{
	        field: 'djbh',
	        title: '单据编号',
	        sortable:true
	    }, {
	        field: 'bt',
	        title: '标题',
	        sortable:true,
	        formatter: function(value, row, index) {	        	
	        	return '<a href="../manager/jcdjDetail.html?lsdjbh='+row.id+'">'+value+'</a>';
		      }
	    }, {
	        field: 'jcdw',
	        title: '寄存单位',
	        sortable:true
	    }, {
	        field: 'kssj',
	        title: '开始寄存时间',
	        sortable:true
	    }, {
	        field: 'jssj',
	        title: '结束时间',
	        sortable:true
	    }, {
	        field: 'bcbmmc',
	        title: '保存部门名称',
	        sortable:true
	    },{
	        field: 'bcrmc',
	        title: '保存人名称',
	        sortable:true
	    },{
	        field: 'xtglymc',
	        title: '协同管理员名称',
	        sortable:true
	    }];

var jccpColTitle = [{
       field: 'lsdjbh',
       title: '单据编号',
       sortable:true
   }, {
       field: 'id',
       title: '藏品编号',
       sortable:true
   }, {
       field: 'cpmc',
       title: '藏品名称',
       sortable:true,
       formatter: function(value, row, index) {	        	
       	return "<a href='../manager/jccpDetail.html?cpbh="+row.id+"'>"+value+"</a>";
	      }
   }, {
       field: 'cpsl',
       title: '藏品数量',
       sortable:true
   }, {
       field: 'cfwz',
       title: '存放位置',
       sortable:true
   }, {
       field: 'kssj',
       title: '开始寄存时间',
       sortable:true
   }, {
       field: 'jssj',
       title: '归还时间',
       sortable:true
   }];
